<script>
import axios from "axios";
const http = axios.create({
  baseURL:'http://localhost:8888',
  timeout:15000,
  headers: {'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'},
})

export default {
  name: "ProductSavePage",
  data(){
    return{
          product: {
            name: null,
            brand: null,
            price: null,
            discount: null,
            stock: null,
          }
    }
  },
  methods: {
    handleSubmit() {
      this.$confirm('确定要提交吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        http.post('/product/save', this.product)
            .then((result) => {
              if (result.data.code === '1') {
                this.$notify.success(result.data.message)
              }
              else if(result.data.code='-1'){
                this.$notify.error((result.data.message))
              }
            })
            .catch((error) => {
              this.$notify.error('服务器请求失败,请稍后重试')
            })
      }).catch(() => {})
    }
  }
}
</script>

<template>
<div>
  <el-card style="width: 800px;margin: 20px auto" >新增商名
    <div>
      <el-form>
        <el-form-item label="商品名称" >
          <el-input v-model="product.name"/>
        </el-form-item>
        <el-form-item label="品牌" >
          <el-input v-model="product.brand"/>
        </el-form-item>
        <el-form-item label="价格" >
          <el-input v-model="product.price"/>
        </el-form-item>
        <el-form-item label="折扣" >
          <el-input v-model="product.discount"/>
        </el-form-item>
        <el-form-item label="库存" >
          <el-input v-model="product.stock"/>
        </el-form-item>
        <el-button type="primary" @click="handleSubmit">提交</el-button>
        <el-button type="danger"> 删除 </el-button>

      </el-form>
    </div>
  </el-card>
</div>
</template>

<style scoped>

</style>